<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/30
 * Time: 18:21
 */
require_once(dirname(__FILE__) . '/../../inc/config.inc.php');
require_once(dirname(__FILE__) . '/../../function.php');
IsModelPriv('member');


$page = isset($_GET['page']) ? intval($_GET['page']) : 0;
$size = isset($_GET['limit']) ? intval($_GET['limit']) : 0;
$dtime = isset($_GET['dtime']) ? htmlspecialchars($_GET['dtime']) : "";
$op = isset($_GET['op']) ? htmlspecialchars($_GET['op']) : "all";

$dtime=trim($dtime);
$manageid = isset($_GET['manageid']) ? intval($_GET['manageid']) : 0;   //用户的身份
$task = isset($_GET['task']) ? intval($_GET['task']) : 0;   //用户的身份
$start_num = ($page - 1) * $size;



$sql="SELECT *  FROM `#@__fee_log` where 1   ";

if ($task>0) {
    $sql .= "  and task='$task' ";
}

if ($manageid>0) {
    $sql .= "  and manageid='$manageid'  ";
}

if ($op=='move') {
    $sql .= "  and op='move'  ";
}
if ($op=='add') {
    $sql .= "  and op='add'  ";
}

if ($dtime != "") {
    $time_arr = explode("~", $dtime);
    if (is_array($time_arr) && count($time_arr) == 2) {
        $start_time = strtotime(trim($time_arr[0]));
        $end_time = strtotime(trim($time_arr[1]))+ 3600 * 24 - 1;
        $sql .= " AND op_time>'$start_time' AND op_time<'$end_time' ";

    }

}



$dosql->Execute($sql,8);
$count=$dosql->GetTotalRow(8);
$sql.=" order by id desc  LIMIT $start_num, $size ";
$dosql->Execute($sql);
while ($row = $dosql->GetArray()) {

    $orderid=$row['orderid'];
    $typename="";
    $school="";
    $truename="";
    $content="";
    if($row['type']=="project"){
        $typename="工程";

        $arr=$dosql->GetOne("select * from `#@__project` where id='$orderid' ");

        if(is_array($arr) &&  isset($arr['id']) ){
            $school=$arr['school'];
            $truename=$arr['truename'];
            $content=$arr['content'];
        }
    }
    if($row['type']=="order"){
        $typename="工单";
        $arr=$dosql->GetOne("select `school`,`truename`,`content` from `#@__order` where id='$orderid' ");
        if(is_array($arr) &&  isset($arr['school']) ){
            $school=$arr['school'];
            $truename=$arr['truename'];
            $content=$arr['content'];
        }
    }
    if($row['type']=="admin"){
        $typename="后台操作";


    }


    $row['addtime'] = GetDateTime($row['op_time']);
    $row['mtruename'] = getManage($row['manageid']);
    $row['ordertype'] = $typename;
    $row['taskname'] =getRepairMode($row['task']);
    $row['school'] =$school;
    $row['truename'] =$truename;
    $row['content'] =$content;
    $row_arr['data'][] = $row;
}
if (empty($row_arr['data'])) {
    $row_arr['data'][] = [];
}
$row_arr['code'] = 0;
$row_arr['msg'] = "success";
$row_arr['count'] = $count;
echo json_encode($row_arr);